package com.qf.business.course.event;

import com.ken.event.action.apply.consumer.IKenEventHandler;
import com.ken.event.action.apply.consumer.KenEvent;
import com.ken.event.standard.entity.KenMessage;
import com.qf.business.course.service.CourseInfoService;
import com.qf.data.course.entity.CourseInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * author Ken
 * create_time 2022/10/19
 */
@KenEvent("courseStop")
@Slf4j
public class CouseStopEventHandler implements IKenEventHandler<Integer> {

    @Autowired
    private CourseInfoService courseInfoService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Override
    public void eventHandler(Integer data, KenMessage kenMessage) {
        log.debug("接收到课程停止事件....{}", data);

        CourseInfo courseInfo = courseInfoService.getById(data);
        courseInfo.setStatus(0);
        courseInfoService.updateById(courseInfo);

        //删除redis
        redisTemplate.delete("course_" + data);
    }
}
